<template>
  <div class="mod-config">
    <div v-if="bookmanages">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="search()">
        <el-form-item>
          <el-select v-model="dataForm.grade" placeholder="会员身份">
            <el-option
              v-for="item in options"
              :key="item.val"
              :label="item.label"
              :value="item.val"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.title" placeholder="职位">
            <el-option
              v-for="item in position"
              :key="item.val"
              :label="item.label"
              :value="item.val"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.memberExpireType" placeholder="请选择会员状态">
            <el-option v-for="item in userType" :key="item.type" :label="item.name" :value="item.type"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input v-model="dataForm.userId" placeholder="uid" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="dataForm.nickname" placeholder="昵称" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="dataForm.phone" placeholder="手机号" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search()">查询</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="dataList" :cell-style="cellStyle" border v-loading="dataListLoading" style="width: 100%;">
        <el-table-column prop="userId" header-align="center" align="center" label="uid"></el-table-column>
        <el-table-column prop="nickname" header-align="center" align="center" label="昵称"></el-table-column>
        <el-table-column prop="coverUrl" header-align="center" align="center" label="头像">
          <template slot-scope="scope">
            <img :src="scope.row.avatar" style="width: 40px;height: 40px;" />
          </template>
        </el-table-column>
        <el-table-column prop="phone" header-align="center" align="center" label="手机号"></el-table-column>
        <el-table-column header-align="center" align="center" label="会员身份">
          <template slot-scope="scope">
            {{scope.row.grade==1 ?'会员':''}}
            {{scope.row.grade==2 ?'经理':''}}
            {{scope.row.grade==3 ?'总监':''}}
          </template>
        </el-table-column>
        <el-table-column prop="memberStatus" header-align="center" align="center" label="会员状态">
          <template slot-scope="scope">
            <span :class="{red: scope.row.memberState==0 }">{{scope.row.memberState==0 ?'过期':'未过期 '}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="memberStatus" header-align="center" align="center" label="过期类型">
          <template slot-scope="scope">
            <span v-if="scope.row.memberState==0" style="color: red;">{{scope.row.memberExpireType==1 ?'正常过期':'退款过期 '}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="title" header-align="center" align="center" label="职位">
          <template slot-scope="scope">
            <span>{{ scope.row.title === 0 ? '班长(正常分销) ' : '' }}</span>
            <span>{{ scope.row.title === 1 ? '班主任' : '' }}</span>
            <span>{{ scope.row.title === 2 ? '班长(禁止分销)' : '' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="memberOrderNum" header-align="center" align="center" label="益伴会员订单数"></el-table-column>
        <el-table-column
          prop="memberSaleVolume"
          header-align="center"
          align="center"
          label="益伴会员销售额"
        ></el-table-column>
        <el-table-column prop="courseOrderNum" header-align="center" align="center" label="轻课课程订单数"></el-table-column>
        <el-table-column
          prop="courseSaleVolume"
          header-align="center"
          align="center"
          label="轻课课程销售额"
        ></el-table-column>
        <!--<el-table-column prop="gmtCreated" header-align="center" align="center" label="退款笔数"></el-table-column>-->
        <!--<el-table-column prop="gmtUpdate" header-align="center" align="center" label="退款金额"></el-table-column>-->
        <el-table-column header-align="center" align="center" label="状态">
          <template slot-scope="scope">
            {{scope.row.isAlive==1 ?'正常':''}}
            {{scope.row.isAlive==0 ?'冻结':''}}
          </template>
        </el-table-column>
        <el-table-column fixed="right" header-align="center" align="center" width="150" label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="showInfo(scope.row.userId)">查看</el-button>
            <el-button type="text" size="small" @click="showList(scope.row)">业绩列表</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper"
      ></el-pagination>
    </div>
    <retail-achievement-info ref="retailAchievementInfo"></retail-achievement-info>
    <retail-achievement-list v-if="achievementList" :id="achievementListUserid" :title="title" @goback="goBack"></retail-achievement-list>
  </div>
</template>

<script>
import RetailAchievementInfo from "./retailAchievementInfo";
import RetailAchievementList from "./retailAchievementList";

export default {
  data() {
    return {
      userType: [],
      achievementList: false,
      achievementListUserid: "",
      options: [
        {
          val: null,
          label: "全部"
        },
        {
          val: "1",
          label: "普通会员"
        },
        {
          val: "2",
          label: "经理"
        },
        {
          val: "3",
          label: "总监"
        }
      ],
      //职位
      position: [
        {
          val: null,
          label: "全部"
        },
        {
          val: "0",
          label: "班长(正常分销)"
        },
        {
          val: "1",
          label: "班主任"
        },
        {
          val: "2",
          label: "班长(禁止分销)"
        },
      ],
      dataForm: {
        key: "",
        rember: "",
        uid: "",
        phone: "",
        nickname: "",
        title:'',
      },
      title:'',
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      bookmanages: true,
      dataListLoading: false,
    };
  },
  components: {
    RetailAchievementInfo,
    RetailAchievementList
  },
  mounted() {
    this.getDataList();
    this.getuserType()
  },
  methods: {
    cellStyle({row, column, rowIndex, columnIndex}) {
      if(row.memberState==0) {
        return 'color: #999'
      }
    },
    getuserType() {
      this.$http({
        url: this.$http.adornUrl("/user/appuser/getMemberExpirationType"),
        method: "get",
        params: this.$http.adornParams()
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.userType = data.data
        }
      });
    },
    search() {
      this.pageIndex = 1
      this.getDataList()
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      let obj = {
        page: this.pageIndex,
        limit: this.pageSize,
        key: this.dataForm.key
      };
      if (this.dataForm.memberExpireType) {
        obj.memberExpireType = this.dataForm.memberExpireType;
      }
      if (this.dataForm.grade) {
        obj.grade = this.dataForm.grade;
      }
      if (this.dataForm.userId) {
        obj.userId = this.dataForm.userId;
      }
      if (this.dataForm.nickname) {
        obj.nickname = this.dataForm.nickname;
      }
      if (this.dataForm.phone) {
        obj.phone = this.dataForm.phone;
      }
     if (this.dataForm.title) {
        obj.title = this.dataForm.title;
      }
      this.$http({
        url: this.$http.adornUrl("/sale/saleRelation/memberGradeList"),
        method: "get",
        params: this.$http.adornParams(obj)
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list;
          this.totalPage = data.page.totalCount;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    showInfo(id) {
      console.log(id)
      this.$nextTick(() => {
        this.$refs.retailAchievementInfo.initData(id);
      });
    },
    showList(data) {
      this.achievementListUserid = data.userId;
      console.log(data.userId)
      this.title = data.title;
      this.bookmanages = false;
      this.achievementList = true;
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    goBack() {
      this.achievementList = false;
      this.bookmanages = true;
    }
  }
};
</script>
<style scoped>
  .weak{
    color: red;
  }
</style>
